package com.sakura.controller;

import com.sakura.dto.QueryCheckRecordDTO;
import com.sakura.dto.QueryHelpRequestDTO;
import com.sakura.dto.UpdateCheckRecordDTO;
import com.sakura.service.CheckRecordService;
import com.sakura.util.R;
import com.sakura.vo.UnCheckProjectRecordVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : Sakura
 * @Date : 2023/11/23 14:19
 * @Description : TODO 检查记录
 */
@Api(value = "/api/record", tags = {"检查记录"})
@RestController
@RequestMapping("/api/record")
//解决跨域问题
@CrossOrigin
public class CheckRecordController {
    @Autowired
    private CheckRecordService recordService;

    /**
     * 根据老人id查询哪些项目还没有完成
     *
     * @param elderlyId:
     * @return Object
     * @author Sakura
     * @date 2023/11/23 14:20
     */

    @ApiOperation(value = "根据老人id查询哪些项目还没有完成", notes = "根据老人id查询哪些项目还没有完成", httpMethod = "GET")
    @GetMapping("/query/plan/{elderlyId}")
    public R list(@ApiParam(value = "老人id", required = true) @PathVariable Long elderlyId) {
        List<UnCheckProjectRecordVO> unCheckProjectVO = recordService.getByElderlyId(elderlyId);
        return R.success(unCheckProjectVO);
    }

    /**
     * 根据老人id查询哪些项目已经完成了
     *
     * @param elderlyId:
     * @return Object
     * @author Sakura
     * @date 2023/11/23 14:20
     */

    @ApiOperation(value = "根据老人id查询哪些项目已经完成了", notes = "根据老人id查询哪些项目已经完成了", httpMethod = "GET")
    @GetMapping("/query/finished/{elderlyId}/{pageNo}")
    public R unFinished(@ApiParam(value = "老人id", required = true) @PathVariable Long elderlyId,
                        @ApiParam(value = "页码   ", required = true) @PathVariable Integer pageNo) {
        List<UnCheckProjectRecordVO> unCheckProjectVO = recordService.getFinishedByElderlyId(elderlyId, pageNo);
        return R.success(unCheckProjectVO);
    }

    /**
     * 根据网格员id查询今天该检测哪些人
     *
     * @param gridId:
     * @param pageNo:
     * @return R
     * @author Sakura
     * @date 2023/12/26 10:10
     */
    @ApiOperation(value = "根据老人id查询哪些项目已经完成了", notes = "根据老人id查询哪些项目已经完成了", httpMethod = "GET")
    @GetMapping("/manager/plan/{gridId}/{pageNo}")
    public R needCheckProject(@ApiParam(value = "网格员id", required = true) @PathVariable Long gridId,
                              @ApiParam(value = "页码   ", required = true) @PathVariable Integer pageNo) {
        return R.success(recordService.getNeedCheckProject(gridId, pageNo));
    }

    /**
     * 查询检查计划详情
     * @param recordId:
     * @return R
     * @author Sakura
     * @date 2023/12/26 13:58
     */
    @ApiOperation(value = "查询检查计划详情", notes = "查询检查计划详情", httpMethod = "GET")
    @GetMapping("/detail/{recordId}")
    public R getCheckRecordDetail(@ApiParam(value = "检查计划id", required = true) @PathVariable Long recordId) {
        return recordService.getCheckRecordDetailById(recordId);
    }

    @ApiOperation(value = "记录检查计划结果", notes = "记录检查计划结果", httpMethod = "POST")
    @PostMapping("/update")
    public R updateCheckRecord(@ApiParam(value = "检查计划id", type = "UpdateCheckRecordDTO",required = true) @RequestBody UpdateCheckRecordDTO updateCheckRecordDTO) {
        return recordService.updateCheckRecord(updateCheckRecordDTO);
    }


    @ApiOperation(value = "分页查询所有测试记录")
    @PostMapping("/list")
    public R list(@ApiParam(value = "分页查询所有测试记录") @RequestBody QueryCheckRecordDTO queryCheckRecordDTO) {
        return recordService.getPage(queryCheckRecordDTO);
    }

}
